﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ChinaGS.Lian.ModuleRemoting;

public partial class recharge_area_paysuccess_unicom : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SysCommon.checkUserLogin();

        if (!IsPostBack)
        {
            String ItemNo = Request["HidItemNo"];
            String cusNo = Request["HidcusNo"];
            String PayMoney = Request["PayMoney"];

            int user_paid_id = DataBaseOperate_SQLServer.execPPaidAtonce(Session["user_id"].ToString(), "3".ToString(), cusNo,
                PayMoney, PayMoney, "0".ToString(), "0".ToString(), "0".ToString(), System.DateTime.Now.ToString(), "none".ToString());

             if (user_paid_id < 0)
             {                
                 LabMessage.Text = "操作失败！原因是：" + RemotingClass.alertExecErroeResult(user_paid_id).ToString() + "，请重试";
                 PanPay.Visible = false;
             }
             else
             {
                 UnicomPackage ucp = RemotingClass.uniComPayMoney(cusNo, ItemNo, System.Convert.ToDouble(PayMoney));
                 //测试使用
                 /*UnicomPackage ucp = new UnicomPackage();
                 ucp.Status = true;
                 ucp.SerialNo = "123456789";
                 ucp.Message = "success";
                 ucp.StatusNo = "00";
                 ucp.ITEMNO = "1234567";
                 ucp.CUSNAME = "denveryee";
                 ucp.CUSNO = cusNo;
                 ucp.CUSSUM = 0;
                 ucp.CHARGE = 0;
                 ucp.PREFLAG = "2";
                 ucp.PREFLAG_CN = "预付费";
                 ucp.PAYNUM = 0;
                 ucp.serverSerialNo = "1234567890";
                 UnicomInvInfo a = new UnicomInvInfo();
                 a.period = "one";
                 a.PreCharge = "100";
                 a.NowCharge = "200";
                 a.NowPay = "100";
                 UnicomInvInfo b = new UnicomInvInfo();
                 b.period = "two";
                 b.PreCharge = "10";
                 b.NowCharge = "20";
                 b.NowPay = "10";
                 UnicomInvInfo[] temp = new UnicomInvInfo[2] { a, b };
                 ucp.InvInfos = temp;*/

                 DataList1.DataSource = ucp.InvInfos;
                 DataList1.DataBind();


                 if (ucp.Status)
                 {
                     //充值成功操作                
                     DataBaseOperate_SQLServer.execPPaidSetStatus(user_paid_id.ToString(), ucp.SerialNo,
                         ucp.CUSNO, ucp.Message, "1".ToString(), SysCommon.getClientIP(), "0".ToString());
                     LabMessage.Text = "恭喜您，您的" + ucp.CUSNO + "账户付款成功：";
                     if (ucp.PREFLAG.Equals("1"))
                     {
                         LabCharge.Text = ucp.CHARGE.ToString();
                         PanUnicomInvInfos.Visible = false;
                         PanUnicomInvInfo.Visible = true;
                     }
                     else
                     {
                         PanUnicomInvInfos.Visible = true;
                         PanUnicomInvInfo.Visible = false;
                     }

                 }
                 else
                 {
                     DataBaseOperate_SQLServer.execPPaidSetStatus(user_paid_id.ToString(), ucp.SerialNo,
                         ucp.CUSNO, ucp.Message, "2".ToString(), SysCommon.getClientIP(), "0".ToString());
                     LabMessage.Text = "操作失败！原因是：" + ucp.Message + "，请稍后重试";
                     PanPay.Visible = false;
                 }            
             
             }                        
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("input_unicom.aspx");
    }
}
